﻿function AzureOnlineTableEntry($initialInfo) {

    var self = this;

    self.name = ko.observable('');

    self.metadata = ko.observableArray([]);
    
    self.setInfo = function ($info) {
        var $content = $info.find('content');
        var $props = $content.children().filterNode('m:properties');
        var $tableName = $props.children().filterNode('d:TableName');
        self.name($tableName.text());
        
        var $meta = $info.find('Metadata').children();
        var meta = [];
        for (var i = 0; i < $meta.length; i++) {
            var $metaItem = $($meta[i]);
            var name = $metaItem.prop('tagName');
            var value = $metaItem.text();
            meta.push({
                name: name,
                value: value
            });
        }

        self.metadata(meta);
    };

    if ($initialInfo) {
        this.setInfo($initialInfo);
    }
}